package com.lzb.compressmaster.activity;

import android.text.TextUtils;
import android.view.View;

import com.blankj.utilcode.util.ToastUtils;
import com.lzb.compressmaster.BaseAc;
import com.lzb.compressmaster.Content;
import com.lzb.compressmaster.R;
import com.lzb.compressmaster.basic.utils.SPUtil;
import com.lzb.compressmaster.databinding.ActivityChangePwdBinding;

public class ChangePwdActivity extends BaseAc<ActivityChangePwdBinding> implements View.OnClickListener {


    @Override
    protected int onCreate() {
        return R.layout.activity_change_pwd;
    }

    @Override
    protected void initView() {
        mDataBinding.ivChangePwdBack.setOnClickListener(view -> getOnBackPressedDispatcher().onBackPressed());

        mDataBinding.tvConfirm.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.tvConfirm) {//确定
            String oldPassword = mDataBinding.etOldPassword.getText().toString().trim();
            String newPassword = mDataBinding.etNewPassword.getText().toString().trim();
            String againPassword = mDataBinding.etPasswordAgain.getText().toString().trim();
            if (TextUtils.isEmpty(oldPassword)) {
                ToastUtils.showShort(getString(R.string.please_input_old_password));
                return;
            }
            if (TextUtils.isEmpty(newPassword)) {
                ToastUtils.showShort(getString(R.string.please_input_new_password));
                return;
            }
            if (TextUtils.isEmpty(againPassword)) {
                ToastUtils.showShort(getString(R.string.please_input_password_again));
                return;
            }
            String password = SPUtil.getString(mContext, Content.myPassword, "");
            if (!oldPassword.equals(password)) {
                ToastUtils.showShort(getString(R.string.password_error));
                return;
            }
            if (!oldPassword.equals(newPassword)) {
                ToastUtils.showShort(getString(R.string.password_is_different));
                return;
            }
            SPUtil.putString(mContext, Content.myPassword, newPassword);
            finish();
        }
    }

    @Override
    protected void initData() {

    }
}